using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SqlServerDriver
{
	public partial class PickObjectForm : Form
	{
		public String SelectedObjectName;
		public PickObjectForm(BrokerObjectCollection brokerObjects, char collectionType, String defaultSelection)
		{
			InitializeComponent();
			SelectedObjectName = "";
			String filterSig = "schemas.microsoft";
			switch (collectionType)
			{
				case 'C':
					foreach (BrokerObjectCollection.Contract c in brokerObjects.Contracts)
						if (c.Name.IndexOf(filterSig) == -1)
							listObjects.Items.Add(c.Name);
					break;
				case 'M':
					foreach (BrokerObjectCollection.MessageType m in brokerObjects.MessageTypes)
						if (m.Name.IndexOf(filterSig) == -1)
							listObjects.Items.Add(m.Name);
					break;
				case 'S':
					foreach (BrokerObjectCollection.Service s in brokerObjects.Services)
						if (s.Name.IndexOf(filterSig) == -1)
							listObjects.Items.Add(s.Name);
					break;
				case 'Q':
					foreach (BrokerObjectCollection.Queue q in brokerObjects.Queues)
						if (q.Name.IndexOf(filterSig) == -1)
							listObjects.Items.Add(q.Name);
					break;
			}
		}

		private void BtnOk_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.OK;
			this.SelectedObjectName = listObjects.Items[listObjects.SelectedIndex].ToString();
			this.Close();
		}

		private void BtnCancel_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}
	}
}